package br.eng.eliseu.gwt.gestaoWeb.server.service.cadastro;

import java.util.List;

import br.eng.eliseu.gwt.gestaoWeb.client.service.EnderecoService;
import br.eng.eliseu.gwt.gestaoWeb.model.endereco.Cidade;
import br.eng.eliseu.gwt.gestaoWeb.model.endereco.Estado;
import br.eng.eliseu.gwt.gestaoWeb.model.endereco.Pais;
import br.eng.eliseu.gwt.gestaoWeb.model.endereco.TipoLogradouro;
import br.eng.eliseu.gwt.gestaoWeb.server.command.generico.GetEntityListCommand;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Singleton;

@Singleton
public class EnderecoServiceImpl extends RemoteServiceServlet implements EnderecoService{

	private static final long serialVersionUID = 603091729501120742L;

	public EnderecoServiceImpl() {
		super();
	}
	
	
	@Inject Injector injector;
	
	@SuppressWarnings("unchecked")
	public List<Pais> listaPaises() throws Exception {
		GetEntityListCommand cmd = injector.getInstance(GetEntityListCommand.class);
		cmd.setNamedQuery("pais.todos");
		return cmd.call();
	}

	@SuppressWarnings("unchecked")
	public List<TipoLogradouro> listaTipoLogradouro() throws Exception {
		GetEntityListCommand cmd = injector.getInstance(GetEntityListCommand.class);
		cmd.setNamedQuery("tipoLogradouro.todos");
		return cmd.call();
	}

	@SuppressWarnings("unchecked")
	public List<Estado> listaEstado(Pais pais) throws Exception {
		GetEntityListCommand cmd = injector.getInstance(GetEntityListCommand.class);
		cmd.setNamedQuery("estado.porPais");
		cmd.addParameter("pais", pais);
		return cmd.call();
	}

	@SuppressWarnings("unchecked")
	public List<Cidade> listaCidade(Pais pais, Estado estado) throws Exception {
		GetEntityListCommand cmd = injector.getInstance(GetEntityListCommand.class);
		cmd.setNamedQuery("cidade.porPaisEstado");
		cmd.addParameter("pais", pais);
		cmd.addParameter("estado", estado);
		return cmd.call();
	}

}
